﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Buddy.BehaviorTree;
using Buddy.Common;
using Buddy.CommonBot.Settings;
using Buddy.Common.Math;
using Buddy.CommonBot;
using Buddy.Navigation;
using Buddy.Swtor;
using Buddy.Swtor.Objects;

using WingIt.Routines;
using WingIt.Routines.Mirrors;

using Action = Buddy.BehaviorTree.Action;


namespace WingIt
{
    [RevisionControlId("$Id: BWcoreFixup.cs 693 2012-08-13 17:05:06Z Chinajade $")]
    public static partial class CreateBTPS
    {
        /// <summary>
        /// <para>"BWcoreFixup" behaviors work around bugs in the BWcore.  These behaviors should be removed as soon as the underlying bug is repaired.</para>
        /// <para>This particular behavior dismounts (if mounted) by starting our rejuvenation spell, then immediately terminating it.</para>
        /// <para>Notes:<list type="bullet">
        /// <item><description><para> * Even when we dismount, BWcore may immediately decide to remount again.</para></description></item>
        /// </list></para>
        /// </summary>
        /// <returns></returns>
        /// 15Jul2012-23:24UTC chinajade
        public static Composite BWcoreFixup_Dismount()
        {
            return (new Decorator(whenMounted => Me.IsMounted && !string.IsNullOrEmpty(CharacterSettings.Instance.MountName),
                new PrioritySelector(
                    //new Action(dismount => { WingIt.Instance.Cast(CharacterSettings.Instance.MountName); return RunStatus.Failure; }) // <sigh> ability doesn't toggle.
                    //// Wait for self-buff ability to come off of cooldown
                    CreateBTPS.StopWithinRangeAndLoS(myTarget => Me, float.MaxValue), // stop moving immediately
                    new Decorator(whenAbilityOnCooldown => Mirror.CooldownTracker.IsOnCooldown(Me.GetMirrorAbility(Me.SelfBuffName())),
                        new Action()),
                    Mirror.Cast(Me.SelfBuffName(), selfBuffOn => Me, selfBuffWhen => true)
                    )));
        }

        /// <summary>
        /// <para>"BWcoreFixup" behaviors work around bugs in the BWcore.  These behaviors should be removed as soon as the underlying bug is repaired.</para>
        /// <para>This particular behavior delays a Routine's pull until a Companion's harvest is complete.</para>
        /// </summary>
        /// <returns></returns>
        /// 15Jul2012-23:24UTC chinajade
        public static Composite BWcoreFixup_WaitForHarvestComplete()
        {
            string myMethodName = Logger.GetMyMethodName();

            return (new Decorator(whenHarvestInProgress => !Me.InCombat && (Me.IsCasting || (Me.IsCompanionInUse() && Me.Companion.IsCasting)),
                new PrioritySelector(
                    // CreateBTPS.IntentNotify(intentThrottleName => myMethodName,
                    //                         intentMessage => string.Format("Waiting for {0} to complete harvesting", Me.Companion.Name),
                    //                         TimeSpan.FromSeconds(5)),
                    new Action()    // wait for harvest to complete
                    ))
                );
        }
    }
}
